package src.clientlogic;

import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

public class ClientsTester {
	


	public static void main(String[] args) throws InterruptedException {
		final int NUMBER_OF_CLIENTS=1;
		final int NUBBER_OF_REQUEST=1000;
		long totalTime=System.nanoTime();
		CountDownLatch cdl=new CountDownLatch(NUBBER_OF_REQUEST*NUMBER_OF_CLIENTS);
		for (int i = 0; i < NUMBER_OF_CLIENTS; i++) {
			new RequestMaker(NUBBER_OF_REQUEST, i, cdl).start();
		}
		cdl.await();
		totalTime-=System.nanoTime();
		System.out.println("Estimate handle time for 1 request is "+(-totalTime/(NUBBER_OF_REQUEST*NUMBER_OF_CLIENTS))+" nanos");
		

	}

}
class RequestMaker extends Thread{
	final int numberOfRequest;
	final int clientId;
	CountDownLatch cdl;

	public RequestMaker(int numberOfRequest, int clientId,CountDownLatch cdl) {
		super();
		this.numberOfRequest = numberOfRequest;
		this.clientId=clientId;
		this.cdl=cdl;
	}
	
	public void run(){
		Client client=new Client("127.0.0.1");
		for (int i = 0; i < numberOfRequest; i++) {
			System.out.println(clientId+" "+i+" "+client.get());
			cdl.countDown();
		}
	}
}

